﻿using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Infrastructure.Imterfaces;
using AuthCenter_HuangJingtao.Read.Api.Application.Command;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler
{
    public class RoleShowCommandHandler : IRequestHandler<RoleShowCommand, ApiResult<List<Roles>>>
    {
        IBaseReponsitory<Roles> Roles;

        public RoleShowCommandHandler(IBaseReponsitory<Roles> Roles)
        {
            this.Roles = Roles;
        }

        public async Task<ApiResult<List<Roles>>> Handle(RoleShowCommand request, CancellationToken cancellationToken)
        {
            var list =await Roles.GetQuery().ToListAsync();
            list=list.Where(x=>x.Role_IsDeleted==false).ToList();
            return new ApiResult<List<Roles>>
            {
                Code = ApiEnum.Success,
                Message = "获取成功",
                Data = list
            };
        }
    }
}
